<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\store\model\jia;

use app\common\model\jia\Feedback as FeedbackModel;
use think\facade\Db;

/**
 * 学习阶段
 * Class Category
 * @package app\store\model
 */
class Feedback extends FeedbackModel
{

    /**
     * 获取所有记录
     * @param array $param
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(array $param = []): \think\Paginator
    {
        // 默认查询参数
        $params = $this->setQueryDefaultValue($param, [
            'status' => -1, // 状态(1显示 0隐藏 -1全部)
            'title' => '',
        ]);
        // 设置检索条件
        $filter                             = [];
        $params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
        !empty($params['title']) && $filter[] = ['name|phone', 'like', '%'.$params['title'].'%'];
        // 查询列表数据
        return $this->with(['images.file', 'user.avatar'])
            ->where($filter)
            ->where('is_delete', 0)
            ->order(['create_time desc'])
         ->paginate(15);
    }

    /**
     * 添加新记录
     * @param $data
     * @return bool
     */
    public function add($data): bool
    {
        $data['store_id'] = self::$storeId;
        return $this->save($data);
    }

    /**
     * 编辑记录
     * @param $data
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit($data): bool
    {
        $data['status'] = 1;

        return $this->save($data) !== false;
    }

    /**
     * 删除记录
     * @return bool
     */
    public function remove($feedbackId): bool
    {
        $this->where('id', $feedbackId)->delete();
        // 删除分类记录
        return true;
    }
}
